package 力扣._6954_统计和小于目标的下标对数目;

import java.util.Comparator;
import java.util.List;

public class Solution2 {
    public int countPairs(List<Integer> nums, int target) {
        //先排序
        int count = 0;
        nums.sort(Comparator.comparingInt(o -> o));
        int i = 0, j = nums.size() - 1;
        while (i < j) {
            while (j > i && nums.get(i) + nums.get(j) >= target) j--;
            count += j - i;
            i++;
        }
        return count;
    }
}
